import request from '@/utils/http';

// 获取文件列表
export function getFilesApi(params) {
  return request({
    url: '/api/files/all',
    method: 'get',
    params,
  });
}

// 文件信息上传
export function fileUpload(data) {
  return request({
    url: '/api/files/upload',
    method: 'post',
    data,
  });
}

// base64 文件上传
export function base64Upload(data) {
  return request({
    url: '/api/files/base64/upload',
    method: 'post',
    data,
  });
}

// 下载二进制文件
export function download(url, callback) {
  return new Promise((resolve, reject) => {
    request
      .get(url, {
        responseType: 'blob',
        timeout: 0,
        onDownloadProgress: event => {
          callback(event);
        },
      })
      .then(
        response => {
          resolve(response);
        },
        err => {
          reject(err);
        }
      );
  });
}
